import type { AxiosRequestConfig, AxiosResponse } from 'axios'

// 通用API响应结构
export interface ApiResponse<T = unknown> {
    code: number
    message: string
    data: T
}

// 分页数据结构
export interface PaginationData<T = unknown> {
    list: T[]
    total: number
    page: number
    pageSize: number
}

// 分页响应结构
export type PaginationResponse<T = unknown> = ApiResponse<PaginationData<T>>

// 请求配置扩展
export interface RequestConfig extends AxiosRequestConfig {
    // 是否显示loading
    showLoading?: boolean
    // 是否显示错误提示
    showError?: boolean
    // 是否需要token
    needToken?: boolean
    // 是否启用缓存
    cache?: boolean
    // 自定义错误处理
    customErrorHandler?: (error: Error) => void
}

// 响应拦截器类型
export interface ResponseInterceptor {
    onFulfilled?: (
        response: AxiosResponse<ApiResponse>,
    ) => AxiosResponse<ApiResponse> | Promise<AxiosResponse<ApiResponse>>
    onRejected?: (error: Error) => Error | Promise<Error>
}

// 请求拦截器类型
export interface RequestInterceptor {
    onFulfilled?: (config: RequestConfig) => RequestConfig | Promise<RequestConfig>
    onRejected?: (error: Error) => Error | Promise<Error>
}

// HTTP方法类型
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'

// 请求参数类型
export interface RequestOptions {
    url: string
    method?: HttpMethod
    params?: Record<string, unknown>
    data?: Record<string, unknown>
    config?: RequestConfig
}
